﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    .form .formValue input.form-control {
        height: 34px;
        line-height: 34px;
    }

    .form-control {
        padding: 0px;
    }

    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }

    .Table {
        width: 100%;
        margin: 0px;
        padding: 0px;
        border-collapse: collapse;
        border-width: 3px 1px 1px;
        table-layout: fixed;
    }
</style>
<script>
    var resultData;
    var workFlowId = $.request("workFlowId");
    var keyValue = $.request("keyValue");
    var workFlowName = $.request("workFlowName");
    var state = $.request("state");

    $(function () {
        GetInit();
        initEntity();
    });

    function initEntity() {
        if (keyValue) {
            $.ajax({
                url: "/WorkFlowSetting/FlowManage/GetDetailByIdJson?keyValue=" + keyValue,
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data != null) {
                        if (data["F_MessageSend"] != null) {
                            $("#F_MessageSend").val(data["F_MessageSend"].split(',')).trigger('change');
                        }

                        if (data["F_OpreationUserId"] != null) {
                            $("#F_OpreationUserId").val(data["F_OpreationUserId"].split(',')).trigger('change');
                        }

                        if (data["F_OpreationType"] != null) {
                            $("#F_OpreationType").val(data["F_OpreationType"].split(',')).trigger('change');
                        }

                        if (data["F_CcUserId"] != null) {
                            $("#F_CcUserId").val(data["F_CcUserId"].split(',')).trigger('change');
                        }

                        $("#F_Id").val(data["F_Id"]);
                        $("#F_WorkFlowId").val(data["F_WorkFlowId"]);
                        $("#F_StepName").val(data["F_StepName"]);

                        $("#F_TimeOutTip").val(data["F_TimeOutTip"]);
                        $("#F_IsFishTime").val(data["F_IsFishTime"]);
                        $("#F_WorkHours").val(data["F_WorkHours"]);
                        //ChangeCityData();
                        $("#F_TimeOutOpreation").val(data["F_TimeOutOpreation"]);
                        $("#F_OpreationStrategy").val(data["F_OpreationStrategy"]);
                        $("#F_ReturnStrategy").val(data["F_ReturnStrategy"]);
                        $("#F_ReturnType").val(data["F_ReturnType"]);
                        $("#F_WorkFlowNo").val(data["F_WorkFlowNo"]);
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        }

        if (state == 'detail') {

            $('.form-control').prop('readonly', true);
        }

        if (state == 'add') {

            $('.form-control').val('');
        }
    }

    function InitControl() {
        debugger
        var F_MessageSend = resultData.F_MessageSend;
        for (var i = 0; i < F_MessageSend.length; i++) {
            $("#F_MessageSend").append("<option value='" + F_MessageSend[i].F_ItemCode + "'>" + F_MessageSend[i].F_ItemName + "</option>");
        }

        var F_OpreationStrategy = resultData.F_OpreationStrategy;
        for (var i = 0; i < F_OpreationStrategy.length; i++) {
            $("#F_OpreationStrategy").append("<option value='" + F_OpreationStrategy[i].F_ItemCode + "'>" + F_OpreationStrategy[i].F_ItemName + "</option>");
        }

        var F_OpreationType = resultData.F_OpreationType;
        for (var i = 0; i < F_OpreationType.length; i++) {
            $("#F_OpreationType").append("<option value='" + F_OpreationType[i].F_ItemCode + "'>" + F_OpreationType[i].F_ItemName + "</option>");
        }

        var F_ReturnStrategy = resultData.F_ReturnStrategy;
        for (var i = 0; i < F_ReturnStrategy.length; i++) {
            $("#F_ReturnStrategy").append("<option value='" + F_ReturnStrategy[i].F_ItemCode + "'>" + F_ReturnStrategy[i].F_ItemName + "</option>");
        }

        var F_ReturnType = resultData.F_ReturnType;
        for (var i = 0; i < F_ReturnType.length; i++) {
            $("#F_ReturnType").append("<option value='" + F_ReturnType[i].F_ItemCode + "'>" + F_ReturnType[i].F_ItemName + "</option>");
        }

        var F_TimeOutOpreation = resultData.F_TimeOutOpreation;
        for (var i = 0; i < F_TimeOutOpreation.length; i++) {
            $("#F_TimeOutOpreation").append("<option value='" + F_TimeOutOpreation[i].F_ItemCode + "'>" + F_TimeOutOpreation[i].F_ItemName + "</option>");
        }

        var F_TimeOutTip = resultData.F_TimeOutTip;
        for (var i = 0; i < F_TimeOutOpreation.length; i++) {
            $("#F_TimeOutTip").append("<option value='" + F_TimeOutTip[i].F_ItemCode + "'>" + F_TimeOutTip[i].F_ItemName + "</option>");
        }

        var F_Users = resultData.F_Users;
        for (var i = 0; i < F_Users.length; i++) {
            $("#F_CcUserId").append("<option value='" + F_Users[i].F_Id + "'>" + F_Users[i].F_Account + "</option>");
            $("#F_OpreationUserId").append("<option value='" + F_Users[i].F_Id + "'>" + F_Users[i].F_Account + "</option>");
        }

        $("#F_OpreationUserId, #F_OpreationType, #F_MessageSend, #F_CcUserId").bindSelect({
            placeholder: "请选择相关内容",
            multiple: true
        });


        //$("#F_TimeOutOpreation, #F_TimeOutTip, #F_OpreationStrategy, #F_ReturnStrategy, #F_ReturnType").bindSelect();
    }

    function GetDictionaries(value, type) {
        if (type == "F_ActivityCityId") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_ActivityCityId.length; i++) {
                for (var j = 0; j < value.split(',').length; j++) {
                    if (j == value.split(',').length - 1) {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName;
                        }
                    } else {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName + ",";
                        }
                    }
                }
            }
            return strHtml;
        } else if (type == "F_ActivityType") {
            for (var i = 0; i < resultData.F_ActivityType.length; i++) {
                if (value == resultData.F_ActivityType[i].F_ItemCode) {
                    return resultData.F_ActivityType[i].F_ItemName;
                }
            }
            return '';
        }
    }

    function ProjectChange(f_fartherId) {
        var Projects = [];
        var siteProjects = resultData.Projects;
        for (var i = 0; i < siteProjects.length; i++) {
            if (siteProjects[i].F_ClientId == f_fartherId) {
                Projects.push({ value: siteProjects[i].F_ProjectName, data: siteProjects[i].F_Id });
            }
        }

        $("#F_ProjectId").autocomplete({
            lookup: Projects,
            onSelect: function (suggestion) {
                $("#hd_ProjectId").val(suggestion.data);
                ProjectInfo(suggestion.data);
            }
        });
    }

    //var contracts;
    //function ProjectInfo(projectId) {
    //    $.ajax({
    //        url: "/ClientManager/ClientInfos/GetProjectInfo?F_Id=" + projectId,
    //        dataType: "json",
    //        async: false,
    //        success: function (data) {
    //            contracts = data;
    //            if (data.length > 1) {
    //                $("#contactArea").show();
    //                $("#contactNum").html(data.length);
    //                $("#contractList").empty();
    //                for (var i = 0; i < data.length; i++) {
    //                    if (i == 0) {
    //                        $("#contractList").append("<li id=" + data[i]["F_Id"] + "><a style=\"cursor:pointer;\" onclick=\"ChangeContract(this)\" class=\"active\">" + data[i]["F_Contact"] + "</a></li>");
    //                        $("#F_Contact").val(data[i]["F_Contact"]);
    //                        $("#F_DepartmentId").val(data[i]["F_DepartmentId"]);
    //                        $("#F_PositionId").val(data[i]["F_PositionId"]);
    //                        $("#F_Phone").val(data[i]["F_Phone"]);
    //                        $("#F_Telephone").val(data[i]["F_Telephone"]);
    //                        $("#F_Mail").val(data[i]["F_Mail"]);
    //                        $("input[name='F_Sex'][value=" + data[i]["F_Sex"] + "]").attr("checked", true);
    //                    } else {
    //                        $("#contractList").append("<li id=" + data[i]["F_Id"] + "><a style=\"cursor:pointer;\" onclick=\"ChangeContract(this)\">" + data[i]["F_Contact"] + "</a></li>");
    //                    }
    //                }
    //            } else {
    //                $("#contactArea").hide();
    //                $("#F_Contact").val(data[0]["F_Contact"]);
    //                $("#F_DepartmentId").val(data[0]["F_DepartmentId"]);
    //                $("#F_PositionId").val(data[0]["F_PositionId"]);
    //                $("#F_Phone").val(data[0]["F_Phone"]);
    //                $("#F_Telephone").val(data[0]["F_Telephone"]);
    //                $("#F_Mail").val(data[0]["F_Mail"]);
    //                $("input[name='F_Sex'][value=" + data[0]["F_Sex"] + "]").attr("checked", true);
    //            }
    //        },
    //        error: function (XMLHttpRequest, textStatus, errorThrown) { }
    //    });
    //}

    function GetInit() {
        $.ajax({
            url: "/WorkFlowSetting/FlowManage/GetDetailItemsJson",
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
                InitControl();
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

    function ChangeClientType() {
        var F_ClientType = $("#F_ClientType").val();
        if (F_ClientType == "1") {
            $("#F_CompanyType").attr("disabled", "disabled");
            $("#F_CompanyType").css("background-color", "#ddd");
            $("#F_MappingId").attr("disabled", "disabled");
            $("#F_MappingId").css("background-color", "#ddd");

            $("#F_IndustryId").removeAttr("disabled");
            $("#F_IndustryId").css("background-color", "#fff");


        } else {
            $("#F_IndustryId").attr("disabled", "disabled");
            $("#F_IndustryId").css("background-color", "#ddd");

            $("#F_CompanyType").removeAttr("disabled");
            $("#F_CompanyType").css("background-color", "#fff");
            $("#F_MappingId").removeAttr("disabled");
            $("#F_MappingId").css("background-color", "#fff");
        }
    }

    function submitForm() {
        debugger
        if (!$('#form1').formValid()) {
            return false;
        }

        if (!validateSubmitForm()) {
            return false;
        }

        var F_CcUserIdList = $("#F_CcUserId").select2("data");
        var F_CcUserId = "";
        for (var i = 0; i < F_CcUserIdList.length; i++) {
            if (i == F_CcUserIdList.length - 1) {
                F_CcUserId += F_CcUserIdList[i].id;
            } else {
                F_CcUserId += F_CcUserIdList[i].id + ",";
            }
        }

        var F_OpreationUserIdList = $("#F_OpreationUserId").select2("data");
        var F_OpreationUserId = "";
        for (var i = 0; i < F_OpreationUserIdList.length; i++) {
            if (i == F_OpreationUserIdList.length - 1) {
                F_OpreationUserId += F_OpreationUserIdList[i].id;
            } else {
                F_OpreationUserId += F_OpreationUserIdList[i].id + ",";
            }
        }

        var F_MessageSendList = $("#F_MessageSend").select2("data");
        var F_MessageSend = "";
        for (var i = 0; i < F_MessageSendList.length; i++) {
            if (i == F_MessageSendList.length - 1) {
                F_MessageSend += F_MessageSendList[i].id;
            } else {
                F_MessageSend += F_MessageSendList[i].id + ",";
            }
        }

        var F_OpreationTypeList = $("#F_OpreationType").select2("data");
        var F_OpreationType = "";
        for (var i = 0; i < F_OpreationTypeList.length; i++) {
            if (i == F_OpreationTypeList.length - 1) {
                F_OpreationType += F_OpreationTypeList[i].id;
            } else {
                F_OpreationType += F_OpreationTypeList[i].id + ",";
            }
        }



        //console.log($('#F_WorkFlowName').val());
        $.submitForm({
            url: "/WorkFlowSetting/FlowManage/SubmitForm?keyValue=" + keyValue,
            param: {
                'F_Id': keyValue,
                'F_WorkFlowId': workFlowId,
                'F_StepName': $('#F_StepName').val(),
                'F_WorkFlowNo': $('#F_WorkFlowNo').val(),
                'F_TimeOutTip': $('#F_TimeOutTip').val(),
                'F_IsFishTime': $('#F_IsFishTime').val(),
                'F_WorkHours': $('#F_WorkHours').val(),
                'F_TimeOutOpreation': $('#F_TimeOutOpreation').val(),
                'F_OpreationType': F_OpreationType,
                'F_OpreationUserId': F_OpreationUserId,
                'F_OpreationStrategy': $('#F_OpreationStrategy').val(),
                'F_ReturnStrategy': $('#F_ReturnStrategy').val(),
                'F_ReturnType': $('#F_ReturnType').val(),
                'F_MessageSend': F_MessageSend,
                'F_CcUserId': F_CcUserId,
                //'WorkFlowName': $.currentWindow().$('#F_WorkFlowName').val(),
                //'WorkFormId': $.currentWindow().$('#F_WorkFormId').val()
            },
            success: function () {

                $.currentWindow().$("#gridList").trigger("reloadGrid");
                //$.closeTab();
            }
        });
    }

    //校验提交表单
    function validateSubmitForm() {
        var F_OpreationType = $('#F_OpreationType').val();
        if (F_OpreationType == null || F_OpreationType == '') {
            $.modalAlert("请先选择处理方式！", "warning");
            return false;
        }

        var F_OpreationUserId = $('#F_OpreationUserId').val();
        if (F_OpreationUserId == null || F_OpreationUserId == '') {
            $.modalAlert("请先选择处理人！", "warning");
            return false;
        }

        var F_MessageSend = $('#F_MessageSend').val();
        if (F_MessageSend == null || F_MessageSend == '') {
            $.modalAlert("请先选择消息发送方式！", "warning");
            return false;
        }

        var F_CcUserId = $('#F_CcUserId').val();
        if (F_CcUserId == null || F_CcUserId == '') {
            $.modalAlert("请先选择抄送人！", "warning");
            return false;
        }

        return true;
    }
</script>
<div id="ProjectsDetail">
    <form id="form1">
        <table class="form">
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">流程顺序</td>
                            <td class="formValue">
                                <input type="text" id="F_WorkFlowNo" name="F_WorkFlowNo" class="form-control required" placeholder="" />
                            </td>
                            <td class="formTitle">步骤名称</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_StepName" name="F_StepName" class="form-control required" placeholder="" />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="formTitle">超期提示</td>
                            <td class="formValue">
                                <select id="F_TimeOutTip" name="F_TimeOutTip" class="form-control required" onchange="">
                                    <option value="">==请选择==</option>
                                </select>
                            </td>
                            <td class="formTitle">工时（小时）：</td>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input type="text" id="F_WorkHours" name="F_WorkHours" class="form-control required" placeholder="" />
                                </div>
                            </td>
                        </tr>
                        <tr>

                            <td class="formTitle">超时处理：</td>
                            <td class="formValue">
                                <select id="F_TimeOutOpreation" name="F_TimeOutOpreation" class="form-control required" onchange="">
                                    <option value="">==请选择==</option>
                                </select>
                            </td>
                            <td class="formTitle">处理方式</td>
                            <td class="formValue">
                                <select id="F_OpreationType" name="F_OpreationType" class="form-control required">
                                    <option></option>
                                </select>
                            </td>
                            <td class="formTitle">处理人</td>
                            <td class="formValue">
                                <select id="F_OpreationUserId" name="F_OpreationUserId" class="form-control required">
                                    <option></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="formTitle">处理策略：</td>
                            <td class="formValue">
                                <select id="F_OpreationStrategy" name="F_OpreationStrategy" class="form-control required" onchange="">
                                    <option value="">==请选择==</option>
                                </select>
                            </td>
                            <td class="formTitle">退回策略：</td>
                            <td class="formValue">
                                <select id="F_ReturnStrategy" name="F_ReturnStrategy" class="form-control required">
                                    <option value="">==请选择==</option>
                                </select>
                            </td>
                            <td class="formTitle">退回类型：</td>
                            <td class="formValue">
                                <select id="F_ReturnType" name="F_ReturnType" class="form-control required">
                                    <option value="">==请选择==</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="formTitle">消息发送方式：</td>
                            <td class="formValue">
                                <select id="F_MessageSend" name="F_MessageSend" class="form-control required" onchange="">
                                    <option></option>
                                </select>
                            </td>
                            <td class="formTitle">抄送人：</td>
                            <td class="formValue">
                                <select id="F_CcUserId" name="F_CcUserId" class="form-control required">
                                    <option></option>
                                </select>
                            </td>

                        </tr>
                    </table>
                </td>
            </tr>

        </table>
    </form>
</div>
